const crypto = require('crypto');
var SHA256 = require("crypto-js/sha256");
const fs = require('fs');
const msg = "channel_id=021&currency_code=CNY&occur_balance=0.11&partner_id=40000039&partner_serial_no=2018103117243976892504&partner_trans_date=20181031&partner_trans_time=172439&prod_name=毛衣&receive_url=http://111.231.87.118:3001/api/getHSPayResult&sendercomp_id=30000001&summary=毛衣1111&targetcomp_id=91000"
const qs = require('qs');
// const key = fs.readFileSync('./decrytKey.txt', 'utf8');
const key =
`-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQDb8dL8OcfQlh1lSfN7G561/6N4q3cFwg7CGBAFlDFh2oK7byGB
g6M7Y88T/EqzUgANDf2UFUgvUVEOReOGtyAxaKrGPReKDWz2SCWF0edSKkl4YYqZ
UIOTVflw7yUsCEj7GuKuplZqQ/0smWj6yfKccPeG/pEp5+w6u60AhtJY2wIDAQAB
AoGAfJl/hCIbn4AbQRFm3PwlqkcbTbYdZGauQ6isEu0EGMJYQ2TOn3d6lp+RZWoM
y4+NtdeSKzzvOtcfSy2umtfNZQL65pZ+iel1wsIYccGQUEKKblZ0NUu6eLi0+Mtk
ujMWU7+c1aby3uHgpVQyXeqFfEWiGol2LzyjIkc4TCUKp+kCQQD6swBWtkW3uEX4
D5pFfFOrIsJ6VlzfLQKGKpxXUtSAM7eREHlD1NFTYznGYkkyvk42iAtasmjhF/cE
mhFhgttPAkEA4JhaRq9foE7LzF0+4Kgg7r08F6j8/HVWCQ+yj/3vvtr1bes+TUWs
BU+hTYd/CRHZ93PRpARQhKFmGWyCAyOWtQJBAI/S7ZjRjQGvaAS9/sVqZB3EHUpO
DY3DprUN8Q9v55V9FgzVJJyzlTt/q3+Sl2fTIc/LEKiBvgWU2BP9x4bnqaUCQDH9
VyKiiDtLLotXOdaRNXtN/WEayOx8RWEQ8GKiV8l4POZxVNWoK0inV7TE8t6W7Zfp
XIEQQMe0kOAZybpfIn0CQEhxEdqiQc+3opAWp8GFB26wd7iZNCM5TmX0/6sltHeL
VexRh2WbuJ9PX/TSq084vfhHgYJFwhP7d55foQu936w=
-----END RSA PRIVATE KEY-----`

const data = SHA256(msg).toString()
console.log(data, 88)
console.log(key, 88)
const signShortStr = data.toUpperCase();
const sign = crypto.createSign('RSA-SHA1');
sign.update(signShortStr);
// sign.end();
const getSignStr = sign.sign({key, passphrase: '123456'}, 'base64');
console.log(getSignStr)
const a = qs.parse('cert_sign=Zfn5zX/ohyw1vNybuajw4ec+ZkHIppAtLkf5IfxL0X5dYuK35345itxSYj3vVHSNchLCZdzivqWpHjB3jU5AN5nZLSMU/jUiWP147KSuXT5KoWK0dhpIbZD62dbPsEBAblEBGrHiX8b1D0I0PH3kknU1HLUAGqWBYtJhxFxJiDI=&channel_id=021&currency_code=CNY&occur_balance=0.11&partner_id=40000039&partner_serial_no=2018103120584258024741&partner_trans_date=20181031&partner_trans_time=205842&prod_name=uu+u&receive_url=http://111.231.87.118:3001/api/+getHSPayResult&summary=uuu&targetcomp_id=91000')
console.log(a, 999)

